package org.taobao.ibatiside.ui.wizard;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.taobao.ibatiside.core.IbatisConstant;

public class IBatisVersionPage extends WizardPage {
	
	private int version= IbatisConstant.VERSION_TWO;
	private Button v2;
	private Button v3;
	
	protected IBatisVersionPage(String pageName) {
		super(pageName);
		setTitle("Version");
		setDescription("choose the version of BATIS");
	}

	@Override
	public void createControl(Composite parent) {
		Composite cp = new Composite(parent, SWT.NONE);
		cp.setLayout(new RowLayout());
		v2 = new Button(cp, SWT.RADIO);
		v2.setText("iBATIS 2.x");
		
		
		v2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				version = IbatisConstant.VERSION_TWO;
			}
		});
		
		v3 = new Button(cp, SWT.RADIO);
		v3.setText("MyBATIS 3.x");
		
		v3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				version = IbatisConstant.VERSION_MYBATIS;
			}
		});
		setControl(cp);
		updateSelection();
	}
	private void updateSelection() {
		v2.setSelection(version==IbatisConstant.VERSION_TWO);
		v3.setSelection(version == IbatisConstant.VERSION_MYBATIS);
	}

	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
		updateSelection();
	}

}
